package com.chengyu.core.controller;


import com.chengyu.core.component.OperationLog;
import com.chengyu.core.dao.ReceiptUserOrderDao;
import com.chengyu.core.entity.CommonPage;
import com.chengyu.core.exception.CommonException;
import com.chengyu.core.exception.ServiceException;

import com.chengyu.core.model.ReceiptUserOrder;
import com.chengyu.core.model.UmsMember;
import com.chengyu.core.entity.CommonResult;
import com.chengyu.core.request.PageParamRequest;
import com.chengyu.core.response.ReceiptUserOrderDetailResponse;
import com.chengyu.core.service.ReceiptUserOrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 订单发票信息 前端控制器
 * </p>
 *
 * @author macro
 * @since 2024-01-17
 */
@RestController
@RequestMapping("/user/receipt/order")
public class ReceiptUserOrderController  extends UserBaseController {
    @Autowired
    private ReceiptUserOrderService receiptUserOrderService;


        @ApiOperation(value = "分页列表")
        @RequestMapping(value = "/list", method = RequestMethod.GET)
        @ResponseBody
        @ApiImplicitParams({
//            @ApiImplicitParam(name = "cid", value = "分类id", dataType = "int"),
                @ApiImplicitParam(name = "type", value = "类型", dataType = "int"),
                @ApiImplicitParam(name = "title", value = "标题", dataType = "string"),
//            @ApiImplicitParam(name = "author", value = "作者", dataType = "string")
        })
        public CommonResult<CommonPage<ReceiptUserOrderDetailResponse>> getList(@Validated ReceiptUserOrder request, @Validated PageParamRequest pageParamRequest) throws ServiceException {

            Integer uid = getCurrentMemberId();
            request.setUid(uid);

            return com.chengyu.core.entity.CommonResult.success(CommonPage.restPage(receiptUserOrderService.getListWidthOrder(request, pageParamRequest)));
        }


        @ApiOperation(value = "详情")
        @ResponseBody
        @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
        public com.chengyu.core.entity.CommonResult<ReceiptUserOrder> detail(@PathVariable(value = "id") Integer id) {
            return com.chengyu.core.entity.CommonResult.success(receiptUserOrderService.getVoByFront(id));
        }



        @ApiOperation(value = "添加编辑")
        @OperationLog
        @RequestMapping(value = {"/add"}, method = RequestMethod.POST)
        public com.chengyu.core.entity.CommonResult<String> editSubmit(@RequestBody @Validated  ReceiptUserOrder receiptUserOrder) throws CommonException, ServiceException {


            UmsMember member = getCurrentMember();
            receiptUserOrder.setUid(getCurrentMemberId());

            receiptUserOrderService.pushReceiptUserOrder(receiptUserOrder);
//		goodsService.publishGoodsNew(getCurrentShop(), publishForm);
            return com.chengyu.core.entity.CommonResult.success(null);
        }


        @ApiOperation(value = "删除")
        @OperationLog
        @ResponseBody
        @RequestMapping(value = {"/del"}, method = RequestMethod.DELETE)
        public com.chengyu.core.entity.CommonResult<String> del(Integer id) throws CommonException, ServiceException {


            receiptUserOrderService.deleteByIdWithMemberId(id,getCurrentMemberId());
//		goodsService.publishGoodsNew(getCurrentShop(), publishForm);
            return com.chengyu.core.entity.CommonResult.success(null);
        }



}


//    @ApiOperation(value = "example")
//	@ResponseBody
//	@RequestMapping(value="/example", method= RequestMethod.GET)
//	public CommonResult<List<ReceiptUserOrder>> example() {
//        ReceiptUserOrder receiptUserOrder=new ReceiptUserOrder();
//        receiptUserOrder.setOrderId("9");
//        receiptUserOrder.setName("牛逼2");
//        receiptUserOrder.setRemark("xxx2");
//        boolean save = receiptUserOrderService.updateById(receiptUserOrder);


//            //查询所有
//            receiptUserOrderService .list();
////根据查询条件查询一个返回实体类对象
//            receiptUserOrderService.getOne(lambdaQueryWrapper);
////分页查询所有
//            receiptUserOrderService.page(pageInfo,lambdaQueryWrapper);
////查询数量
//            receiptUserOrderService .count();
////根据ID查list集合
//            receiptUserOrderService .listByIds();
////根据ID删除
//            receiptUserOrderService .removeById();
//            receiptUserOrderService .removeByIds();
////修改
//            receiptUserOrderService .update();
//            userMapper.updateById(实体类);
////新增
//            receiptUserOrderService .save();
//            userMapper.insert(实体类);
////批量新增
//            receiptUserOrderService .saveBatch(集合);

//        }

